//1.判断token,有token，说明
loadInitData();
function loadInitData() {
    var token = localStorage.getItem("token");
    console.log("token:"+token);
    $.ajax({
        type: "get",
        url: "index",
        headers: {'token': token},
        success: function (result) {
            console.log(result)
            var data = result.data;
            console.log("map:" + data);
            var loginCustomer = data.loginCustomer;
            if (loginCustomer != null) {
                var customerId = loginCustomer.customerId;
                var url = "/demo/order?customerId="+customerId;
                $(".head-user").hide();
                $(".user-menu").html('<li class="text"><a href='+url+'>个人中心</a></li>\n' +
                    '                 <li class="text" id="return"><button style="border: none">退出登录</button></li>');
                $(".user-info").show();
                $(".myorder").click(function (){
                    $(".message").hide();
                    $(".order").show();
                    $(".coupon").hide();
                })

                $("#return").click(function (){
                    var token = localStorage.removeItem("token");
                    window.location.href = "http://localhost:8080/demo/index.jsp";
                })

                $(".del-order").click(function (){
                    var orderId = document.querySelector(".OrderId").textContent;
                    console.log("===================================="+orderId);
                    $.ajax({
                        type: "get",
                        url: "delOrder",
                        data:{
                            orderId:orderId,
                        },
                        success: function (result){
                            console.log(result);
                            location.reload(true);
                        }
                    })
                })

                $(".my-msg").click(function (){
                    $(".order").hide();
                    $(".message").show();
                    $(".coupon").hide();
                })

                $(".my-coupon").click(function (){
                    $(".order").hide();
                    $(".message").hide();
                    $(".coupon").show();
                })
            } else {
                $(".head-user").show();
                $(".user-info").hide();
            }

        }
        })
}

